package cn.hs.service.impl;

import cn.hs.entity.User;
import cn.hs.mapper.UserMapper;
import cn.hs.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author mujiale
 * @Date 2024年10月24日 10:09
 * @Version 1.0
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public PageInfo<User> selectAll(Integer pageNum, Integer pageSize, User user) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> users = userMapper.selectAll(user);
        PageInfo pageInfo = new PageInfo(users);
        return pageInfo;
    }

    @Override
    public int insert(User user) {
        String username = user.getUsername();
        User user1 = userMapper.selectName(username);
        if (user1 != null){
            return 0;
        }
        return userMapper.insert(user);
    }

    @Override
    public int update(User user) {
        return userMapper.update(user);
    }

    @Override
    public int delete(Integer id) {
        return userMapper.delete(id);
    }

    @Override
    public List<User> select(User user) {
        return userMapper.selectAll(user);
    }

    @Override
    public User selectNameAndPwd(String username, String password) {
        return userMapper.selectNameAndPwd(username,password);
    }
}
